home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 12 / BBS in a box XII-1.iso / Files / Tele / Pete Johnson / AreaTrix 1.0.4<source>.sit / PurgeFiles.p < prev   
Encoding:
Text File  |  1990-03-27  |  4.6 KB  |  132 lines  |  [TEXT/PJMM]

  1. unit PurgeFiles;
  2.  
  3. interface
  4.  
  5.  
  6. uses
  7.     Globals, NewFileUtils, HelloTabby;
  8.  
  9. procedure PurgeFiles (GenericPath: str255);
  10.  
  11. var
  12. DeleteForwards: boolean;
  13.  
  14. implementation
  15.  
  16. { ------------------------------------------------------ }
  17.  
  18. procedure PurgeFiles;
  19.  
  20. {    Sets up a FwdHandleArray of up to 500 records with four fields:    }
  21. {                                                                                            }
  22. {    FileName, SendFilesName    :     str64                                            }
  23. {    Valid, IgnoreMe            :    boolean                                            }
  24. {                                                                                            }
  25. {    The ':Tabby:AreaTrix WorkFile' is read line by line, filling        }
  26. {    in the FwdHandleArray.                                                            }
  27. {                                                                                            }
  28. {    Then the array is analyzed. Initially both boolean fields are set    }
  29. {    to false. If the SendFilesxxx/yyy.bbs file can be opened and if    }
  30. {    it contains the FileName, then Valid is set to true.                    }
  31. {                                                                                            }
  32. {    The array is stepped through with two counters. The first goes        }
  33. {    from 1 to the last array element. The second goes from the            }
  34. {    Counter1+1 to the last array element. Each time through the            }
  35. {    Counter1 loop, PendingFwd is set to false. If the IgnoreMe field    }
  36. {    of FwdHandleArray[Counter1] is false, it is set to true; if the    }
  37. {    Valid field of FwdHandleArray[Counter1] is true, PendingFwd is        }
  38. {    set to true; Counter2 is used to scan the remaining elements,        }
  39. {    looking for matches in the FileName field; if IgnoreMe is false    }
  40. {    and FileName matches FwdHandleArray[Counter1].FileName then            }
  41. {    IgnoreMe is set to true; if FwdHandleArray[Counter2].Valid is        }
  42. {    true then PendingFwd is set to true. At the end of each Counter1    }
  43. {    loop if PendingFwd is false, FwdHandleArray[Counter1].FileName        }
  44. {    is deleted.                                                                            }
  45.  
  46.     const
  47.         MAXARRAY = 500;
  48.  
  49.     type
  50.         FwdRecord = record
  51.                 FileName, SendFilesName: string[64];
  52.                 Valid, IgnoreMe: boolean
  53.             end;
  54.         FwdPtr = ^FwdRecord;
  55.         FwdHdl = ^FwdPtr;
  56.  
  57.     var
  58.         Index1, Index2, FwdLimit, WorkRef, SendRef, vRefNum: integer;
  59.         FwdHdlArray: array[1..MAXARRAY] of FwdHdl;
  60.         PendingFwd: boolean;
  61.         OneLine, VolName: str255;
  62.         Err: OSErr;
  63.  
  64.     begin
  65.         Err := GetVol(@VolName, vRefNum);        { Get volume ref # for default volume }
  66.         MakeTextFile(':Tabby:AreaTrix Workfile');
  67.         Err := FSOpen(':Tabby:AreaTrix WorkFile', vRefNum, WorkRef);
  68.         Index1 := 0;
  69.         while not AtEOF(WorkRef) & (Index1 < MAXARRAY) do
  70.             begin
  71.                 Err := ReadALine(WorkRef, OneLine);
  72.                 if Err = NoErr then
  73.                     begin
  74.                         Index1 := succ(Index1);
  75.                         FwdHdlArray[Index1] := FwdHdl(NewHandle(sizeOf(FwdRecord)));
  76.                         HLock(Handle(FwdHdlArray[Index1]));
  77.                         FwdHdlArray[Index1]^^.FileName := copy(OneLine, 1, pos(TAB, OneLine) - 1);
  78.                         FwdHdlArray[Index1]^^.SendFilesName := copy(OneLine, pos(TAB, OneLine) + 1, 255);
  79.                         FwdHdlArray[Index1]^^.Valid := false;
  80.                         FwdHdlArray[Index1]^^.IgnoreMe := false;
  81.                         Err := FSOpen(concat(GenericPath, FwdHdlArray[Index1]^^.SendFilesName), vRefNum, SendRef);
  82.                         while not AtEOF(SendRef) & (Err = NoErr) do
  83.                             begin
  84.                                 Err := ReadALine(SendRef, OneLine);
  85.                                 if Err = NoErr then
  86.                                     if pos(FwdHdlArray[Index1]^^.FileName, OneLine) > 0 then
  87.                                         FwdHdlArray[Index1]^^.Valid := true;
  88.                             end;        {    while not AtEOF(SendRef) & (Err = NoErr)    }
  89.                         Err := FSClose(SendRef);
  90.                     end;    {    if read WorkRef line OK        }
  91.             end;        {    while not AtEOF(WorkRef)    }
  92.         FwdLimit := Index1;
  93.  
  94.         for Index1 := 1 to FwdLimit do
  95.             begin
  96.                 PendingFwd := false;
  97.                 if (FwdHdlArray[Index1]^^.IgnoreMe = false) then
  98.                     begin
  99.                         FwdHdlArray[Index1]^^.IgnoreMe := true;
  100.                         if FwdHdlArray[Index1]^^.Valid = true then
  101.                             PendingFwd := true;
  102.                         for Index2 := Index1 + 1 to FwdLimit do
  103.                             if (FwdHdlArray[Index2]^^.IgnoreMe = false) & (FwdHdlArray[Index1]^^.FileName = FwdHdlArray[Index2]^^.FileName) then
  104.                                 begin
  105.                                     FwdHdlArray[Index2]^^.IgnoreMe := true;
  106.                                     if FwdHdlArray[Index2]^^.Valid = true then
  107.                                         PendingFwd := true
  108.                                 end;{    long if (FwdHdlArray[Index2]^^.IgnoreMe = false) etc. construction    }
  109.                         if (not PendingFwd) & DeleteForwards then
  110.                             Err := FSDelete(concat(GenericPath, FwdHdlArray[Index1]^^.FileName), vRefNum);
  111.                     end;        {    if (FwdHdlArray[Index1]^^.IgnoreMe = false)    }
  112.             end;        {    for Index1 := 1 to FwdLimit    }
  113.  
  114.         Err := FSClose(WorkRef);
  115.  
  116.         Err := FSDelete(':Tabby:AreaTrix WorkFile', vRefNum);
  117.         MakeTextFile(':Tabby:AreaTrix Workfile');
  118.         Err := FSOpen(':Tabby:AreaTrix WorkFile', vRefNum, WorkRef);
  119.         for Index1 := 1 to FwdLimit do
  120.             begin
  121.                 if (FwdHdlArray[Index1]^^.Valid) then
  122.                     begin
  123.                         OneLine := concat(FwdHdlArray[Index1]^^.FileName, TAB, FwdHdlArray[Index1]^^.SendFilesName);
  124.                         Err := MyWriteLine(WorkRef, OneLine);
  125.                     end;
  126.                 HUnlock(Handle(FwdHdlArray[Index1]));
  127.                 DisposHandle(Handle(FwdHdlArray[Index1]));
  128.             end;
  129.  
  130.         Err := FSClose(WorkRef);
  131.     end;
  132. end.